package models

import (
	"github.com/jinzhu/gorm"
	"kop/libs/database"
	"kop/modules/port/entity"
	"time"
)

func CreateReport(dB *gorm.DB, report entity.PortReport) error {

	return dB.Create(&report).Error
}

func GetReports(roleID int32, limit int) []entity.PortReport {

	var data []entity.PortReport
	if err := database.DB.Where(entity.PortReport{RoleID: roleID}).Limit(limit).Order("id DESC").Find(&data).Error; err != nil {
		panic(err)
	}

	return data
}

func DeleteReports(dB *gorm.DB, time time.Time) error {

	return dB.Where("created_at < ?", time).Delete(entity.PortReport{}).Error
}
